using NUnit.Framework;
using RestSharp;
using StoryQ;
using TripleA.Core.Extensions.Web;
using TripleA.StoryQ;

namespace TripleA.Tests.Web
{

    [TestFixture]
    public class GetTests : BddFeature
    {
        protected override Feature DescribeFeature()
        {
            return new Story("Testing Http Get requests")
                .InOrderTo("Make Http Get requests")
                .AsA("Consumer of http response")
                .IWant("to ensure that the call is made correctly");
        }

        [Test]
        public void HttpGetWithArgs()
        {
            using (var domain = new WebDomain())
            {
                var request = new HttpStepConfig
                                  {
                                      Args = new {arg1 = "arg1", arg2 = "arg2"},
                                      Method = Method.GET,
                                      Uri = "http://localhost:81/test.htm"
                                  };

                Feature.WithScenario("Make a GET request with querystring args")
                    .Tag("GET")
                    .Tag("Http")
                    .Given(domain.TheRequest, request)
                    .When(domain.TheRequestIsMade)
                    .Then(domain.TheRequestQuerystringShouldBe_, "?arg1=arg1&arg2=arg2")
                    .ExecuteWithReport();
            }
        }

        [Test]
        public void HttpGetWithUrlInjection()
        {
            using (var domain = new WebDomain())
            {
                var request = new HttpStepConfig
                                  {
                                      Args = new {seg1 = "path1", seg2 = "path2"},
                                      Method = Method.GET,
                                      Uri = "http://localhost:81/{seg1}/{seg2}/test.htm",
                                      InjectArgsIntoUrl = true
                                  };

                Feature.WithScenario("Make a GET request args injected into url")
                    .Tag("GET")
                    .Tag("Http")
                    .Given(domain.TheRequest, request)
                    .When(domain.TheRequestIsMade)
                    .Then(domain.TheRequestPathShouldBe_, "/path1/path2")
                    .ExecuteWithReport();
            }
        }
    }
}